<?php
namespace app\post\controller\admin;
use app\common\controller\Admin;
use app\common\traits\ControllerCurd;
use think\Request;
use app\common\annotation\NodeAnnotation;
/**
 * @NodeAnnotation(
 *     title="文章标签",
 *     parent="post/admin.index",
 *     is_menu=0,
 *     is_view=0,
 *     auth=1,
 * )
 */
class Tag extends Admin
{
    use ControllerCurd;
    public $model = '';
    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\post\model\Tag();
    }

    /**
     * @NodeAnnotation(
     *     title="文章标签",
     *     parent="post/admin.tag",
     *     MenuRoot="post/admin.index"
     * )
     */
    public function index(Request $request)
    {
        $keywords  = $request->param("keywords");

        $where = [];

        if($keywords) array_push($where,['name',"like","%$keywords%"]);

        $tagList = $this->model->where($where)->paginate();

        $this->assign([
            "tagList" => $tagList,
            "search"  => [
                "keywords" => $keywords
            ]
        ]);
        return view();
    }

    /**
     * @NodeAnnotation(
     *     title="添加文章标签",
     *     parent="post/admin.tag",
     *     MenuRoot="post/admin.index",
     *     is_menu = 0
     * )
     */
    public function addtag()
    {
        $this->add(url("post/admin.tag/index"));
        return view();
    }

    /**
     * @NodeAnnotation(
     *     title="编辑文章标签",
     *     parent="post/admin.tag",
     *     MenuRoot="post/admin.index",
     *     is_menu = 0
     * )
     */
    public function edittag($id=0)
    {
        $tag = $this->model->find($id);

        $this->edit(url("post/admin.tag/index"));

        $this->assign([
            "tag" => $tag
        ]);

        return view();
    }

    /**
     * @NodeAnnotation(
     *     title="删除文章标签",
     *     parent="post/admin.tag",
     *     MenuRoot="post/admin.index",
     *     is_menu = 0
     * )
     */
    public function deltag()
    {
        $this->del();
    }

}